package top.javawa.token.domain.primary;

import java.util.List;
import java.util.Optional;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import top.javawa.token.domain.primary.AccessToken;

/**
 * @author aaron
 */
public interface AccessTokenRepository extends CrudRepository<AccessToken, Long> {

  /**
   * 按照公众号appID查找
   *
   * @param appId 公众号APPID
   * @return List 授权列表
   */
  Optional<List<AccessToken>> findByAppId(String appId);

  @Query("select at from AccessToken as at where at.appId like ?1%")
  List<AccessToken> findByAndSort(String appId, Sort sort);

  @Query("select at from AccessToken as at where at.appId like ?1%")
  List<AccessToken> findByPage(String appId, Pageable pageable);
}
